import axios from 'axios';

// 1. 初始状态.
const state = () => ({
    instances: [],
    selectedInstance: {},
});

// 2. 计算属性.
const getters = {};

// 3. 异步修改.
const actions = {
    loadInstances({ state }, service) {
        axios.get(`/pageList?serviceName=${service}`).then((data) => {
            state.instances = data.data;
        });
    },
};

// 4. 同步修改.
const mutations = {
    changeInstance(state, instance) {
        state.selectedInstance = instance;
    },
};

// 5. 模块导出.
export default {
    namespaced: true,
    state,
    getters,
    actions,
    mutations,
};
